using System;
using System.Collections;
using System.ComponentModel;
namespace Fcdbas.WinUI.Design
{
	internal class InheritedPropertyDescriptor : PropertyDescriptor
	{
		private object m_originalValue;
		private PropertyDescriptor m_baseProperty;
		public override System.Type ComponentType
		{
			get
			{
				return this.m_baseProperty.ComponentType;
			}
		}
		public override bool IsReadOnly
		{
			get
			{
				return this.m_baseProperty.IsReadOnly;
			}
		}
		public override System.Type PropertyType
		{
			get
			{
				return this.m_baseProperty.PropertyType;
			}
		}
		public object OriginalValue
		{
			get
			{
				return this.m_originalValue;
			}
			set
			{
				if (value == null || value.GetType().IsValueType || value.GetType().IsPrimitive)
				{
					this.m_originalValue = value;
					return;
				}
				if (value is System.Collections.ICollection)
				{
					this.m_originalValue = new object[((System.Collections.ICollection)value).Count];
					((System.Collections.ICollection)value).CopyTo((System.Array)this.m_originalValue, 0);
					return;
				}
				if (value is System.ICloneable)
				{
					this.m_originalValue = ((System.ICloneable)value).Clone();
				}
			}
		}
		public InheritedPropertyDescriptor(PropertyDescriptor baseProperty, object component) : base(baseProperty)
		{
			this.m_baseProperty = baseProperty;
			this.SaveOriginalValue(component);
			if (baseProperty.Name == "Items"  && baseProperty.GetType().FullName == "System.ComponentModel.Design.InheritedPropertyDescriptor")
			{
				PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(component.GetType())[baseProperty.Name];
				System.Collections.ArrayList arrayList = new System.Collections.ArrayList(propertyDescriptor.Attributes);
				System.Attribute[] attributeArray = (System.Attribute[])arrayList.ToArray(typeof(System.Attribute));
				this.AttributeArray = attributeArray;
				if (this.m_originalValue == null)
				{
					this.OriginalValue = baseProperty.GetValue(component);
				}
			}
		}
		public override object GetValue(object component)
		{
			return this.m_baseProperty.GetValue(component);
		}
		public override void SetValue(object component, object value)
		{
			this.m_baseProperty.SetValue(component, value);
		}
		public override bool ShouldSerializeValue(object component)
		{
			if (this.m_originalValue == null)
			{
				return this.m_baseProperty.ShouldSerializeValue(component);
			}
			object value = this.m_baseProperty.GetValue(component);
			if (this.m_originalValue is System.Collections.ICollection && value is System.Collections.ICollection)
			{
				return this.ShouldSerializeCollection((System.Collections.ICollection)this.m_originalValue, (System.Collections.ICollection)value);
			}
			return !object.Equals(this.m_originalValue, value);
		}
		public override bool CanResetValue(object component)
		{
			return this.ShouldSerializeValue(component);
		}
		public override void ResetValue(object component)
		{
			if (this.m_originalValue == null)
			{
				this.m_baseProperty.ResetValue(component);
				return;
			}
			this.m_baseProperty.SetValue(component, this.m_originalValue);
		}
		private void SaveOriginalValue(object component)
		{
			if (this.m_baseProperty.ShouldSerializeValue(component))
			{
				this.OriginalValue = this.m_baseProperty.GetValue(component);
			}
		}
		private bool ShouldSerializeCollection(System.Collections.ICollection coll1, System.Collections.ICollection coll2)
		{
			if (coll1.Count != coll2.Count)
			{
				return true;
			}
			if (coll1.Count == 0)
			{
				return false;
			}
			System.Collections.ArrayList arrayList = new System.Collections.ArrayList(coll1);
			foreach (object current in coll2)
			{
				arrayList.Remove(current);
			}
			return arrayList.Count > 0;
		}
	}
}
